package com.inventive.jmscache.server;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Topic;
import javax.jms.TopicSubscriber;

/**
 * Created by IntelliJ IDEA.
 */
public class JmsCacheTopicSubscriber extends JmsCacheMessageConsumer implements TopicSubscriber {

    private String subscriptionId;

    public JmsCacheTopicSubscriber(JmsCacheSession session, JmsCacheDestination destination) {
        super(session, destination);
    }

    public JmsCacheTopicSubscriber(JmsCacheSession session, JmsCacheDestination destination, String subscriptionId) {
        super(session, destination);
        this.subscriptionId = subscriptionId;
    }

    public JmsCacheTopicSubscriber(JmsCacheSession session, JmsCacheDestination destination, String subscriptionId, String messageSelector, boolean noLocal) {
        super(session, destination, messageSelector, noLocal);
        this.subscriptionId = subscriptionId;
    }

    public JmsCacheTopicSubscriber(JmsCacheSession session, JmsCacheDestination destination, String messageSelector, boolean noLocal) {
        super(session, destination, messageSelector, noLocal);
    }

    public Topic getTopic() throws JMSException {
        return (JmsCacheTopic)destination;
    }

    public boolean getNoLocal() throws JMSException {
        return noLocal;
    }

    @Override
    protected Message doReceive(Long timeoutMillis) throws JMSException {
        if (null == timeoutMillis) {
            return destination.receive(subscriptionId);
        } else {
            return destination.receive(timeoutMillis);
        }
    }
}
